const fs = require("fs");
const path = require("path");

const fileName = path.resolve(__dirname, "test.txt");
const filename2 = path.resolve(__dirname, "testbak.txt");
const readstream = fs.createReadStream(fileName);
const writestream = fs.createWriteStream(filename2);
readstream.on("data", (data) => {
  console.log(data.toString(), "zz");
});
readstream.pipe(writestream);

// fs.readFile(fileName, (err, data) => {
//   if (err) {
//     console.error(err);
//     return;
//   }
//   console.log(data.toString());
// });
// const content = "我读我自己\n";
// const opt = {
//   flag: "a", w覆盖
// };
// fs.writeFile(fileName, content, opt, (err) => {
//   if (err) return console.error(err);
// });
// fs.exists(fileName, (exist) => {
//   console.log(exist);
// });

//标准输入输出
// process.stdin.pipe(process.stdout);
// const http = require("http");
// const server = http.createServer((req, res) => {
//   if (req.method == "POST") {
//     req.pipe(res);
//   }
// });
// server.listen(9999, (res) => {
//   console.log(res);
// });
